package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.domain.ZhDeptInfo;
import com.ruoyi.common.service.IZhDeptInfoService;
import com.ruoyi.system.domain.ZhGuide;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ZhNotice;
import com.ruoyi.system.service.IZhNoticeService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 公告 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-04-26
 */
@Controller
@RequestMapping("/system/zhNotice")
public class ZhNoticeController extends BaseController
{
    private String prefix = "system/zhNotice";
	
	@Autowired
	private IZhNoticeService zhNoticeService;

	@Autowired
	private IZhDeptInfoService zhDeptInfoService;

	@RequiresPermissions("system:zhNotice:edit")
	@GetMapping("wangrditor")
	public String wangrditor(
			Integer id,
			Model model) {
		//todo 随便修改id都能进来

		ZhNotice zhNotice = zhNoticeService.selectZhNoticeById(id);
		model.addAttribute("item" , zhNotice != null ? zhNotice : new ZhNotice());
		return prefix + "/wangrditor";
	}

	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhNotice:view")
	@GetMapping()
	public String zhNotice(ZhNotice zhNotice,ModelMap mmap)
	{
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhNotice.getParams())));
		return prefix + "/zhNotice";
	}
	
	/**
	 * 查询公告列表
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhNotice:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ZhNotice zhNotice,ModelMap mmap)
	{
		startPage();
        List<ZhNotice> list = zhNoticeService.selectZhNoticeList(zhNotice);
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhNotice.getParams())));
		return getDataTable(list);
	}
	
	
	/**
	 * 导出公告列表
	 */
	@RequiresPermissions("system:zhNotice:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZhNotice zhNotice)
    {
    	List<ZhNotice> list = zhNoticeService.selectZhNoticeList(zhNotice);
        ExcelUtil<ZhNotice> util = new ExcelUtil<ZhNotice>(ZhNotice.class);
        return util.exportExcel(list, "zhNotice");
    }
	
	/**
	 * 新增公告
	 */
	@DataScope(tableAlias = "l")
	@GetMapping("/add")
	@RequiresPermissions("system:zhNotice:add")
	public String add(ZhNotice zhNotice,ModelMap mmap)
	{
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhNotice.getParams())));
		return prefix + "/add";
	}
	
	/**
	 * 新增保存公告
	 */
	@RequiresPermissions("system:zhNotice:add")
	@Log(title = "公告", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ZhNotice zhNotice)
	{		
		return toAjax(zhNoticeService.insertZhNotice(zhNotice));
	}

	/**
	 * 修改公告
	 */
	@DataScope(tableAlias = "l")
	@GetMapping("/edit/{id}")
	@RequiresPermissions("system:zhNotice:edit")
	public String edit(ZhNotice zhNotice,@PathVariable("id") Integer id, ModelMap mmap)
	{
		mmap.put("zhNotice", zhNoticeService.selectZhNoticeById(id));
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhNotice.getParams())));
		return prefix + "/edit";
	}
	
	/**
	 * 修改保存公告
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhNotice:edit")
	@Log(title = "公告", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ZhNotice zhNotice)
	{		
		return toAjax(zhNoticeService.updateZhNotice(zhNotice));
	}
	
	/**
	 * 删除公告
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhNotice:remove")
	@Log(title = "公告", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(ZhNotice zhNotice,String ids)
	{		
		return toAjax(zhNoticeService.deleteZhNoticeByIds(ids));
	}
	
}
